package com.lx.shopping.web;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lx.bean.Result;
import com.lx.bilibili.entity.Product;
import com.lx.bilibili.entity.ProductEx;
import com.lx.shopping.dao.CategoryMapper;
import com.lx.shopping.dao.ProductExMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("product")
public class ProductController {

    @Autowired
    ProductExMapper productMapper;

    @Autowired
    CategoryMapper categoryMapper;

    @RequestMapping("getProducts")
    public Result getProduct(){
        return new Result(1,"查询成功", productMapper.selectList(null));
    }

    @RequestMapping("getProductById")
    public Result getProductById(Integer id){
        return new Result(1,"查询成功", productMapper.selectProductById(id));
    }

    @RequestMapping("orderGetProduct")
    public Product orderGetProduct(int id){
        return productMapper.selectById(id);
    }

    @RequestMapping("getProductType")
    public Result getProductType(){
        return new Result(1,"查询成功", categoryMapper.selectList(null));
    }

    @RequestMapping("getProductByType")
    public Result getProductByType(int id){
        LambdaQueryWrapper<Product> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Product::getCid, id);
        List<Product> products = productMapper.selectList(lqw);
        return new Result(1,"查询成功", products);
    }
}
